import { ref,reactive,toRefs } from 'vue';
import  axios  from 'axios';

interface resModel {
    loading?:boolean;
    loaded?:boolean;
    result?:any;
    error?:any;
}

function useHttpRequestCentralized(url:string){
    let res = reactive({loading:true,loaded:false,result:null,error:null});

    axios.get(url).then((res:any) => {
        res = reactive({
            loading:false,
            loaded:true,
            result:res.data,
            error:null
        })
    }).catch((e:any)=>{
        res = reactive({
            loading:true,
            loaded:false,
            result:null,
            error:e
        })
    })

    const refData = toRefs(res);
    return {...refData};
    
}

export default useHttpRequestCentralized